﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SCCN.BLL;
using SCCN.DAL;
using SCCN.Utility;
using System.Text;

public partial class list : System.Web.UI.Page
{
    ArticleBLL bllArticle = ArticleBLL.getInstance();
    CategoryBLL bllCategory = CategoryBLL.getInstance();
    AdvertisementBLL bllAdvertisement = AdvertisementBLL.getInstance();
    AdSpaceBLL bllAdSpace = AdSpaceBLL.getInstance();
    public string currentPosition = string.Empty;
    public string bannerImages = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsPostBack)
        //{
        Bind();
        BindRpt();
        //}
    }

    /// <summary>
    /// 读取广告位
    /// </summary>
    void Bind()
    {
        SC_AdSpace objAdSpace = bllAdSpace.GetAdSpaceByName("列表页头部广告位");
        List<SC_Advertisement> list = bllAdvertisement.GetAdvertisementByAdSpaceId(objAdSpace.Id);
        StringBuilder str = new StringBuilder();
        str.Append("<ul class=\"slide_nav\">");
        int i = 1;
        foreach (SC_Advertisement var in list)
        {
            if (i == 1)
            {
                str.Append("<li><a href=\"" + var.TargetUrl + "\" class=\"current\">0" + i + "</a></li>");
            }
            else
            {
                str.Append("<li><a href=\"" + var.TargetUrl + "\">0" + i + "</a></li>");
            }
            i++;
        }
        str.Append("</ul><div class=\"slide_box\">");
        i = 0;
        foreach (SC_Advertisement var in list)
        {
            str.Append("<a href=\"#\"><img src=\"" + var.PicSrc + "\" alt=\"\" /></a>");
        }
        str.Append("</div>");
        bannerImages = str.ToString();
    }


    void BindRpt()
    {
        SC_Article obj = new SC_Article();
        int categoryId = 0;
        int.TryParse(HttpHelper.GetParameters("categoryid", HttpHelper.MethodType.GET), out categoryId);
        if (categoryId > 0)
        {
            SC_Category obj_Category = bllCategory.GetCategoryByID(categoryId);
            currentPosition = "<li><a href='list.aspx?categoryid=" + obj_Category.Id + "' >" + obj_Category.CategoryName + "</a></li>";
        }
        else
        {
            currentPosition = "<li><a href='list.aspx' >所有文章</a></li>";
        }
        obj.CategoryId = categoryId;
        obj.ArticleContent = string.Empty;
        obj.ArticleTitle = string.Empty;
        obj.KeyWord = HttpUtility.HtmlDecode(HttpHelper.GetParameters("keyword", HttpHelper.MethodType.POST));
        obj.Tag = string.Empty;
        obj.ArticleContent = string.Empty;
        int rowCount = 0;
        this.rptList.DataSource = bllArticle.GetArticleByCondition(obj, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out rowCount);
        this.rptList.DataBind();
        this.AspNetPager1.RecordCount = rowCount;
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindRpt();
    }
}